﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; 
using System.Web.Util;

namespace Sharp
{
    public class RequestValidation : RequestValidator
    {
        public RequestValidation() { }

        protected override bool IsValidRequestString(
            HttpContext context, string value,
            RequestValidationSource requestValidationSource, string collectionKey,
            out int validationFailureIndex)
        {

            if (context.Request.Path.Contains("*"))
                context.Response.Redirect(context.Request.RawUrl.Replace(context.Request.Path, context.Request.Path.Replace("*", "0")), true);

            validationFailureIndex = -1;  //Set a default value for the out parameter.

            //This application does not use RawUrl directly so you can ignore the check.
            if (requestValidationSource == RequestValidationSource.RawUrl)
                return true;
            bool isParanoid = false;

            if (!isParanoid)
                return true;
            //All other HTTP input checks are left to the base ASP.NET implementation.
            else
            {
                return base.IsValidRequestString(context, value, requestValidationSource,
                                                 collectionKey, out validationFailureIndex);
            }
        }
    }
}
